/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.constant;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * DECORATION_COUPON 美容劵
 * DISCOUNT_COUPON 满减券
 * MERCHANT_COUPON 商铺劵
 * CATEGORY_COUPON 品类券
 * SKU_COUPON 单品券
 * ALL_COUPON 通用券
 * SHIPMENT_COUPON 免邮券
 * UPKEEP_COUPON 保养券
 * CASH_COUPON 现金券
 * OFFLINE_COUPON 线下券
 * @author joewee
 * @version 1.0.0
 * @Date 2017/11/3 13:19
 */
public class CouponTypes implements Serializable, EnumerationType {

    private static final long serialVersionUID = -6454775353773729477L;
    private static final Map<String, CouponTypes> TYPES = new LinkedHashMap<String, CouponTypes>();
    private String type;
    private String friendlyType;

    public static final CouponTypes DECORATION_COUPON = new CouponTypes("DECORATION_COUPON", "美容劵");
    public static final CouponTypes DISCOUNT_COUPON = new CouponTypes("DISCOUNT_COUPON", "满减券");
    public static final CouponTypes MERCHANT_COUPON = new CouponTypes("MERCHANT_COUPON", "商铺劵");
    public static final CouponTypes CATEGORY_COUPON = new CouponTypes("CATEGORY_COUPON", "品类券");
    public static final CouponTypes SKU_COUPON = new CouponTypes("SKU_COUPON", "单品券");
    public static final CouponTypes ALL_COUPON = new CouponTypes("ALL_COUPON", "通用券");
    public static final CouponTypes SHIPMENT_COUPON = new CouponTypes("SHIPMENT_COUPON", "免邮券");
    public static final CouponTypes UPKEEP_COUPON = new CouponTypes("UPKEEP_COUPON", "保养券");
    public static final CouponTypes CASH_COUPON = new CouponTypes("CASH_COUPON", "现金券");
    public static final CouponTypes OFFLINE_COUPON = new CouponTypes("OFFLINE_COUPON", "线下券");

    public static CouponTypes getInstance(final String type) {
        return TYPES.get(type);
    }

    public CouponTypes() {
    }

    public CouponTypes(final String type, final String friendlyType) {
        setType(type);
        this.friendlyType = friendlyType;
    }

    private void setType(final String type) {
        this.type = type;
        if (!TYPES.containsKey(type)) {
            TYPES.put(type, this);
        }
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public String getFriendlyType() {
        return friendlyType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CouponTypes that = (CouponTypes) o;

        if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) return false;
        return getFriendlyType() != null ? getFriendlyType().equals(that.getFriendlyType()) : that.getFriendlyType() == null;
    }

    @Override
    public int hashCode() {
        int result = getType() != null ? getType().hashCode() : 0;
        result = 31 * result + (getFriendlyType() != null ? getFriendlyType().hashCode() : 0);
        return result;
    }
}
